package com.waghost.bridalgown.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.waghost.bridalgown.dao.LogsDao;
import com.waghost.bridalgown.entity.Logs;
import com.waghost.bridalgown.entity.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
// 日志
@RestController
@CrossOrigin
@RequestMapping("/logs")
public class LogsController {

    @Autowired
    private LogsDao logsDao;

    @GetMapping("/list")
    public Result list() {
        List<Logs> logs = logsDao.selectList(null);
        int z = 0, s = 0, g = 0, c = 0;
        for (Logs log : logs) {
            switch (log.getType()) {
                case 1:
                    z++;
                    break;
                case 2:
                    s++;
                    break;
                case 3:
                    g++;
                    break;
                case 4:
                    c++;
                    break;
            }
        }
        HashMap<String, Integer> objectObjectHashMap = new HashMap<>();
        objectObjectHashMap.put("z", z);
        objectObjectHashMap.put("s", s);
        objectObjectHashMap.put("g", g);
        objectObjectHashMap.put("c", c);
        return Result.success(objectObjectHashMap);
    }
    @GetMapping("/get/{uuid}")
    public Result getLogs(@PathVariable Integer uuid) {
        List<Logs> logs = logsDao.selectList(new QueryWrapper<Logs>().eq("uuid", uuid));
        int z = 0, s = 0, g = 0, c = 0;
        for (Logs log : logs) {
            switch (log.getType()) {
                case 1:
                    z++;
                    break;
                case 2:
                    s++;
                    break;
                case 3:
                    g++;
                    break;
                case 4:
                    c++;
                    break;
            }
        }
        HashMap<String, Integer> objectObjectHashMap = new HashMap<>();
        objectObjectHashMap.put("z", z);
        objectObjectHashMap.put("s", s);
        objectObjectHashMap.put("g", g);
        objectObjectHashMap.put("c", c);
        return Result.success(objectObjectHashMap);
    }

    @GetMapping("/get/{uuid}/{type}")
    public Result getLogs(@PathVariable Integer uuid,@PathVariable("type")Integer type) {
        List<Logs> logs = logsDao.selectList(new QueryWrapper<Logs>().eq("uuid", uuid).eq("type",type));
        return Result.success(logs);
    }

}
